<?php

header("content-type: text/html; charset=iso-8859-1;", true);

$dbHost = "127.0.0.1:3306";
$dbUser = "root";
$dbPass = "babilonia";
$dbData = "reservas";

$conn = mysql_connect($dbHost,$dbUser,$dbPass) or die(mysql_error());
mysql_select_db($dbData,$conn) or die(mysql_error());

mysql_query("SET NAMES 'utf8';");

session_start();

$user=$_REQUEST['j_username'];
$password=$_REQUEST['j_password'];

$query="SELECT * FROM tab_login WHERE Usuario='$user' AND Senha='$password'";
$sql_select=mysql_query($query) or die (mysql_error());

if(mysql_num_rows($sql_select)) {
	$dados= @mysql_fetch_array($sql_select);
	$_SESSION["Nome"] = stripslashes($dados["Nome"]);
	$_SESSION["IDUsuario"] = stripslashes($dados["IDUsuario"]);
	
	$id = $_SESSION["IDUsuario"];
	if($id == 7) {
		echo "{success: true, errors: { reason: 'equipamento'}}"; // nao eh um erro, eh so uma flag pro redirect
	} else {
		echo "{success: true, errors: { reason: 'sala'}}"; // dido
	}
}

else {
    echo "{success: false}";
}

?>